﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;

namespace IHISCETeim.BLL
{
    /// <summary>
    /// 2.应收帐款销售类型更改记录表(FTradeSalesType)
    /// </summary>
    public class FTradeSalesTypeController : BaseController
    {
        /// <summary>
        /// 获取所有历史的销售类型记录
        /// </summary>
        /// <param name="FTradeID"></param>
        /// <returns></returns>
        public static List<FTradeSalesTypeInfo> GetAllByFTradeID(int FTradeID)
        {
            return CBO.FillCollection<FTradeSalesTypeInfo>( FTradeSalesTypeDAL.GetAllByFTradeID(FTradeID));
        }
        /// <summary>
        /// 获取明细
        /// </summary>
        /// <param name="FTradeSalesId"></param>
        /// <returns></returns>
        public static FTradeSalesTypeInfo GetByFTradeSalesId(int FTradeSalesId)
        {
            return CBO.FillObject< FTradeSalesTypeInfo >(FTradeSalesTypeDAL.GetByFTradeSalesId(FTradeSalesId));
        }
       
        ///// <summary>
        ///// 变更销售类型
        ///// 1.如将全额改成短信分期等.
        ///// 改变后,保留原有的销售类型信息
        ///// 
        ///// 如果原有的销售类型已充值过,则必需先进行调帐,才能变更
        ///// </summary>
        ///// <param name="FTradeID"></param>
        ///// <param name="OldFTradeSalesId">原来的销售类型ID</param>
        ///// <param name="objSalesType">新的销售类型</param>
        ///// <param name="listAgeDetails">对应的帐龄明细</param>
        ///// <returns></returns>
        //public static List<string> UpdateSaleType(int FTradeID, int OldFTradeSalesId, FTradeSalesTypeInfo objSalesType, List<FTradeAgeDetailInfo> listAgeDetails)
        //{
        //    //string cMsg=  FTradeReceivablesDAL.CheckCanChange(FTradeID);
        //    //if (cMsg != "")
        //    //    return cMsg;
        //    ///是否有冲过帐,如果有则需进行调帐操作
        //    //1.获取原冲帐记录
        //    string sqlwhere = string.Format(" FTradeID={0} ", FTradeID);
        //    DataTable dt = FTradeBalanceController.GetAddAdjustingList(sqlwhere);

        //    FTradeCatheringInfo objCat = new FTradeCatheringInfo();
        //    List<int> FbalanceIds = new List<int>();
        //    if (dt.Rows.Count>0)
        //    {
        //        //1.获取原冲帐记录
        //       // string sqlwhere = string.Format(" FTradeID={0} ", FTradeID);
        //        //DataTable dt = FTradeBalanceController.GetAddAdjustingList(sqlwhere);
               
        //        Decimal BalanceMoneys = 0m;
        //        foreach (DataRow dr in dt.Rows)
        //        {
        //            FbalanceIds.Add(Convert.ToInt32(dr["FbalanceId"]));
        //            BalanceMoneys += Convert.ToDecimal(dr["AdjustingMoney"]);//总冲帐款
        //        }
        //        //2.调帐后新的的收款记录
        //        FTradeReceivablesInfo objRec = FTradeReceivablesController.GetByFTradeID(FTradeID);
        //       // FTradeCatheringInfo objCat = new FTradeCatheringInfo();
        //        objCat.FCTitle = objRec.JiHao + "变更销售类型调帐款";
        //        objCat.ShoukuanRiQi = DateTime.Now;
        //        objCat.JingXiaoShang = objRec.JingXiaoShang;
        //        objCat.JinE = BalanceMoneys;
        //        objCat.KuanXiangLeiXing = "调帐";
        //        objCat.RealName = OUserController.CurrentUser.RealName;
        //        objCat.IsAdjustable = false;
        //        objCat.State = "未冲完";
        //        objCat.Remark = objRec.JiHao + "变更销售类型调帐款";
        //        objCat.SourceTag = "系统";
        //    }

        //    return FTradeSalesTypeDAL.UpdateSaleType(FTradeID, OldFTradeSalesId, objSalesType, listAgeDetails, dt.Rows.Count, objCat, FbalanceIds);
        //}

        //public static List<string> UpdateSaleType2(int FTradeID, int OldFTradeSalesId, FTradeReceivablesInfo objTrade, FTradeSalesTypeInfo objSalesType, List<FTradeAgeDetailInfo> listAgeDetails)
        //{
        //    //string cMsg=  FTradeReceivablesDAL.CheckCanChange(FTradeID);
        //    //if (cMsg != "")
        //    //    return cMsg;
        //    ///是否有冲过帐,如果有则需进行调帐操作
        //    //1.获取原冲帐记录
        //    string sqlwhere = string.Format(" FTradeID={0} ", FTradeID);
        //    DataTable dt = FTradeBalanceController.GetAddAdjustingList(sqlwhere);

        //    FTradeCatheringInfo objCat = new FTradeCatheringInfo();
        //    List<int> FbalanceIds = new List<int>();
        //    if (dt.Rows.Count > 0)
        //    {
        //        //1.获取原冲帐记录
        //        // string sqlwhere = string.Format(" FTradeID={0} ", FTradeID);
        //        //DataTable dt = FTradeBalanceController.GetAddAdjustingList(sqlwhere);

        //        Decimal BalanceMoneys = 0m;
        //        foreach (DataRow dr in dt.Rows)
        //        {
        //            FbalanceIds.Add(Convert.ToInt32(dr["FbalanceId"]));
        //            BalanceMoneys += Convert.ToDecimal(dr["AdjustingMoney"]);//总冲帐款
        //        }
        //        //2.调帐后新的的收款记录
        //        FTradeReceivablesInfo objRec = FTradeReceivablesController.GetByFTradeID(FTradeID);
        //        // FTradeCatheringInfo objCat = new FTradeCatheringInfo();
        //        objCat.FCTitle = objRec.JiHao + "变更销售类型调帐款";
        //        objCat.ShoukuanRiQi = DateTime.Now;
        //        objCat.JingXiaoShang = objRec.JingXiaoShang;
        //        objCat.JinE = BalanceMoneys;
        //        objCat.KuanXiangLeiXing = "调帐";
        //        objCat.RealName = OUserController.CurrentUser.RealName;
        //        objCat.IsAdjustable = false;
        //        objCat.State = "未冲完";
        //        objCat.Remark = objRec.JiHao + "变更销售类型调帐款";
        //        objCat.SourceTag = "系统";
        //    }

        //    return FTradeSalesTypeDAL.UpdateSaleType2(OldFTradeSalesId, objTrade,objSalesType, listAgeDetails, dt.Rows.Count, objCat, FbalanceIds);
        //}
    }
}
